﻿using UnityEngine;
using UnityEngine.SceneManagement;

public class SelectPlayPanelModel : BaseComponentModel
{
    private bool isInvalid = false;
    public SelectPlayPanelModel()
    {

    }

    public void OnClickClassicMode()
    {
        if (isInvalid)
        {
            return;
        }
        isInvalid = true;
        SceneManager.LoadSceneAsync("PlayStandardChess").completed += (AsyncOperation ao) =>
        {
            UIManager.GenerateUIFoundation();
            UIManager.OpenUI("SelectCampPanel", typeof(SelectCampPanel), new SelectCampPanelModel(), null);
        };
    }

    public void OnClickThreeMode()
    {
        if (isInvalid)
        {
            return;
        }
        isInvalid = true;
        SceneManager.LoadSceneAsync("PlayThreeKingdomsChess").completed += (AsyncOperation ao) =>
        {
            UIManager.GenerateUIFoundation();
            UIManager.OpenUI("TKSelectCampPanel", typeof(TKSelectCampPanel), new TKSelectCampPanelModel(), null);
        };
    }

    public void OnClickExit()
    {
        UIManager.OpenUI("ConfirmPanel", typeof(ConfirmPanel), new ConfirmPanelModel(Exit, "确定退出？"), null);
    }

    public void Exit()
    {
#if UNITY_EDITOR
        UnityEditor.EditorApplication.isPlaying = false;      
#else
        Application.Quit();         
#endif
    }
}